package com.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 日志工具类
 *
 * @author zyf
 */
public class LogUtil {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    protected static String TRACE = "TRACE";
    protected static String DEBUG = "DEBUG";
    protected static String WARN = "WARN";
    protected static String INFO = "INFO";
    protected static String ERROR = "ERROR";

    /**
     *
     * @param logType  输出级别
     * @param message  输出信息
     */
    protected void logMsg(String logType, String message) {
        switch (logType.toLowerCase()) {
            case "info":
                logger.debug(message); break;
            case "debug":
                logger.debug(message); break;
            case "warn":
                logger.warn(message); break;
            case "error":
                logger.error(message); break;
            case "trace":
                logger.trace(message); break;
            default:
                logger.trace(message);
        }
    }

    /**
     *
     * @param logType   输出级别
     * @param message   输出消息
     * @param args      占位参数
     */
    protected void logMsg(String logType, String message, Object... args) {
        switch (logType.toLowerCase()) {
            case "info":
                logger.info(message, args); break;
            case "debug":
                logger.debug(message, args); break;
            case "warn":
                logger.warn(message, args); break;
            case "error":
                logger.error(message, args); break;
            case "trace":
                logger.trace(message); break;
            default:
                logger.trace(message);
        }
    }

    /**
     *
     * @param logType   输出日志类别
     * @param message   输出消息
     */
    protected void logMsg(LogType logType, String message) {
        logMsg(logger, logType, message);
    }

    /**
     *
     * @param logType   输出日志类别
     * @param message   输出消息
     * @param args      占位参数
     */
    protected void logMsg(LogType logType, String message, Object ...args) {
        switch (logType) {
            case Info:
                logger.info(message, args); break;
            case Debug:
                logger.debug(message, args); break;
            case Warn:
                logger.warn(message, args); break;
            case Error:
                logger.error(message, args); break;
            case Trace:
                logger.trace(message, args); break;
            default:
                logger.trace(message, args);
        }
    }

    /**
     *
     * @param logger    logger
     * @param logType   输出类别
     * @param message   输出消息
     */
    protected void logMsg(Logger logger, LogType logType, String message) {
        switch (logType) {
            case Info:
                logger.info(message); break;
            case Debug:
                logger.debug(message); break;
            case Warn:
                logger.warn(message); break;
            case Error:
                logger.error(message); break;
            case Trace:
                logger.trace(message); break;
            default:
                logger.trace(message);
        }
    }

    /**
     * @author zyf
     * 日志级别
     */
    public enum LogType {

        Trace("Trace"), Debug("Debug"), Info("Info"), Warn("Warn"), Error("Error");

        private String logType;

        LogType(String logType) {
            this.logType = logType;
        }

        public String getLogType() {
            return logType;
        }
    }
}


